<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>用户列表</title>
<script type="text/javascript" src='<c:url value="/js/boot.js"></c:url>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>' />
<script type="text/javascript">
	
</script>
<style type="text/css">
html, body {
	height: 100%;
	width: 100%;
	border: 0;
	overflow: hidden;
	background-origin: padding-box;
	background-clip: border-box;
}

html, body {
	margin: 0;
	padding: 0;
	border: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}
</style>
</head>

<body>
<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-top-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td><a class="mini-button" id="resetBtn" iconCls="icon-reset"
					plain="true" onclick="reloadList">刷新</a><span class="separator"></span>
					<a id="removeBlackBtn" class="mini-button" iconCls="icon-undo" plain="true"
					onclick="removeBlack" visible="false">撤销拉黑</a></td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div id="datagrid1" class="mini-datagrid gridFull"
			borderStyle="border:0;" showReloadButton="true" pagesize="100"
			sizeList="[20,50,100,200]" allowCellWrap="true"
			allowHeaderWrap="true" idField="No" multiSelect="true"
			showPager="true" allowAlternating="true"
			ondrawcell="ondatagrid1DrawCell" onrowdblclick="gridRowDbClick"
			style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
			collapseGroupOnLoad="false" showColumnsMenu="true"
			showFilterRow="true" onshowrowdetail="onShowRowDetail">
			<div property="columns">
				<div type="indexcolumn" width="40px"></div>
				<div name="checkcolumn" type="checkcolumn"></div>
				<div field="Action" width="70px" headerAlign="center" align="center">
					<a class="mini-button" property="filter" id="removeBtn"
						iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch">清除
					</a>
				</div>
				<div field="PHONE" width="100px" headerAlign="center" align="left">
					手机号<input id="filter0" property="filter"
						class="mini-buttonedit searchbox" style="width: 100%;"
						onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
				</div>
				<div field="NICKNAME" width="100px" headerAlign="center"
					align="left">
					用户名<input id="filter4" property="filter"
						class="mini-buttonedit searchbox" style="width: 100%;"
						onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
				</div>
				<div field="USERNAME" width="65px" headerAlign="center"
					align="left">
					姓名<input id="filter1" property="filter"
						class="mini-buttonedit searchbox" style="width: 100%;"
						onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
				</div>
				<div field="SEX" width="50px" headerAlign="center" align="center">
					性别<input id="filter2" property="filter"
						class="mini-buttonedit searchbox" style="width: 100%;"
						onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
				</div>
				<div name="BANKNAME" field="BANKNAME" width="100px" headerAlign="center"
					align="left" allowSort="true">银行</div>
				<div name="ACCOUNTBANK" field="ACCOUNTBANK" width="140px" headerAlign="center"
					align="left" allowSort="true">开户行</div>
				<div name="ACCOUNT" field="ACCOUNT" width="65px" headerAlign="center"
					align="left" allowSort="true">账户名</div>
				<div name="IDCARD" field="IDCARD" width="140px" headerAlign="center"
					align="left" allowSort="true">身份证</div>
				<div field="AREA" width="100px" headerAlign="center" align="left">
					地区<input id="filter3" property="filter"
						class="mini-buttonedit searchbox" style="width: 100%;"
						onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
				</div>
				<div name="LS" field="LS" width="200px" headerAlign="center"
					align="left" allowSort="true">律所</div>
				<div name="FUWUTYPEID" field="FUWUTYPEID" width="65px"
					headerAlign="center" align="center" allowSort="true">
					擅长法律<br />业务类型
				</div>
				<div name="ZYZNUM" field="ZYZNUM" width="140px" headerAlign="center"
					align="center" allowSort="true">执业证号</div>
				<div field="REGISTTIME" width="85px" dateFormat="yyyy-MM-dd"
					headerAlign="center" align="center" allowSort="true">注册日期</div>
				<div field="Operate" width="140px" headerAlign="center"
					align="center">操作</div>
				<div name="emptyCol" width='100%' headerAlign="center"
					align="center" cellStyle="padding:0;"></div>
			</div>
		</div>
	</div>


	<script type="text/javascript">
		mini.parse();

		var rootPath = '${rootPath}';
		var type = '${type}';
		var inBlackList = '${inBlackList}';

		var filterHelper = gridFilter();
		var datagrid1 = mini.get("datagrid1");
		var removeBlackBtn = mini.get("removeBlackBtn");
		var filter0 = mini.get("filter0");
		var filter1 = mini.get("filter1");
		var filter2 = mini.get("filter2");
		var filter3 = mini.get("filter3");
		var filter4 = mini.get("filter4");

		$(function() {
			//loadGrid1();
			if(inBlackList == '1'){
				removeBlackBtn.show();
			}
			onselect();
		});

		function loadGrid1() {
			var filterData = filterHelper.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var url = "<c:url value='/userMng/userData/' />" + type + "/"
					+ inBlackList;
			datagrid1.load(url);
			datagrid1.load(postData, function() {
				if (type == "1") {
					datagrid1.hideColumn("LS");
					datagrid1.hideColumn("FUWUTYPEID");
					datagrid1.hideColumn("ZYZNUM");
				}else if(type == '2' || type == '3'){
					datagrid1.hideColumn("BANKNAME");
					datagrid1.hideColumn("ACCOUNTBANK");
					datagrid1.hideColumn("ACCOUNT");
					datagrid1.hideColumn("IDCARD");
				}
			});
		}

		function onselect() {
			var filterValue0 = filter0.getValue();
			var filterValue1 = filter1.getValue();
			var filterValue2 = filter2.getValue();
			var filterValue3 = filter3.getValue();
			var filterValue4 = filter4.getValue();
			filterHelper.clearFilterData();
			if (filterValue0 != "") {
				var filterdata = filterHelper.formFilterData("PHONE",
						filterValue0, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue1 != "") {
				var filterdata = filterHelper.formFilterData("USERNAME",
						filterValue1, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue2 != "") {
				var filterdata = filterHelper.formFilterData("SEX",
						filterValue2, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue3 != "") {
				var filterdata = filterHelper.formFilterData("SEX",
						filterValue3, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (filterValue4 != "") {
				var filterdata = filterHelper.formFilterData("NICKNAME",
						filterValue4, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			loadGrid1();
		}
		function removeSearch() {
			filter0.setValue();
			filter0.setText();
			filter1.setValue();
			filter1.setText();
			filter2.setValue();
			filter2.setText();
			filter3.setValue();
			filter3.setText();
			filter3.setValue();
			filter3.setText();
			filterHelper.clearFilterData();
			loadGrid1();
		}
		
		function ondatagrid1DrawCell(e) {
			var row = e.row;
			var field = e.field;

			if (field == "Action") {
				var phoneNo = row.PHONE;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:showDetail(\'' + phoneNo
						+ '\')">[查看]</a>';
			}

			if (field == "Operate") {
				var phoneNo = row.PHONE;
				var checked = row.CHECKED;
				var htmlStr = "";
				if(checked == 0){
					htmlStr += '<a class="aTagUnderLine" href="javascript:checkConfirm(\'' + phoneNo
							+ '\',1)">[通过审核]</a>&nbsp;';
				}else if(checked == 1){
					htmlStr += '<a class="aTagUnderLine" href="javascript:checkConfirm(\'' + phoneNo
							+ '\',0)">[反审核]</a>&nbsp;';
				}else{
				}
				if (row.INBLACKLIST == 0) {
					htmlStr += '<a class="aTagUnderLine" href="javascript:pull_black(\'' + phoneNo
							+ '\')">[拉黑]</a>';
				} else {
					htmlStr += '<a class="aTagUnderLine" href="javascript:pull_white(\'' + phoneNo
							+ '\')">[撤销拉黑]</a>';
				}
				e.cellHtml = htmlStr;
			}
			if(field == "FUWUTYPEID"){
				if(row.FUWUTYPEID==1){
					e.cellHtml='婚姻家庭';
				}else if(row.FUWUTYPEID==2){
					e.cellHtml='交通事故';
				}else if(row.FUWUTYPEID==3){
					e.cellHtml='继承纠纷';
				}else if(row.FUWUTYPEID==4){
					e.cellHtml='刑事辩护';
				}else if(row.FUWUTYPEID==5){
					e.cellHtml='劳动仲载';
				}else if(row.FUWUTYPEID==6){
					e.cellHtml='消费权益';
				}else if(row.FUWUTYPEID==7){
					e.cellHtml='房屋拆迁';
				}else if(row.FUWUTYPEID==8){
					e.cellHtml='债权债务';
				}else{
					e.cellHtml='其他问题';
				}
			}
		}
		function reloadList(){
			datagrid1.reload();
		}
		function gridRowDbClick(e){
			var row = e.row;
			var phoneNo = row.PHONE;
			showDetail(phoneNo);
		}
		function showDetail(phoneNo) {
			var url = null;
			if(type == 1){
				url = "<c:url value='/userMng/userDetail/' />" + phoneNo;
			}else if(type == 2 || type == 3){
				url = "<c:url value='/userMng/lawyerDetail/' />" + phoneNo;
			}else{
				return;
			}
			mini.open({
				url : url,
				title : "用户详细",
				width : 800,
				height : 600,
				onload : function() {
					var iframe = this.getIFrameEl();
					var data = {
						action : "new"
					};
					//iframe.contentWindow.SetData(data);
				},
				ondestroy : function(action) {
				}
			});
		}

	
		function pull_black(phoneNos) {
			mini.confirm("确定拉黑?", "确定", function() {
				if (action == "ok") {
					var url = "<c:url value='/userMng/toblack/'/>"+type;
					$.ajax({
						url : url,
						method : "post",
						dataType : "json",
						data : {
							'phoneNos' : phoneNos,
							'state' : "1"
						},
						success : function(data) {
							if (data) {
								//mini.alert("已拉黑！");
								datagrid1.reload();
							}
						},
						error : function() {
							mini.alert("操作出现错误！")
						}
					});
				}
			});
		}
		function pull_white(phoneNos) {
			mini.confirm("确定撤销拉黑?", "确定", function() {
				if (action == "ok") {
					var url = "<c:url value='/userMng/towhite/'/>"+type;
					$.ajax({
						url : url,
						method : "post",
						dataType : "json",
						data : {
							'phoneNos' : phoneNos,
							'state' : "0"
						},
						success : function(data) {
							if (data) {
								//mini.alert("已撤销！");
								datagrid1.reload();
							}
						},
						error : function() {
							mini.alert("操作出现错误！")
						}
					});
			}
			});
		}
		function checkConfirm(phoneNo,checked) {
			var infor = checked==1 ? '确定通过审核？' : '确定反审核？';
			mini.confirm(infor, "确定", function(action) {
				if (action == "ok") {
					var url = "<c:url value='/userMng/checkConfirm'/>";
					$.ajax({
						url : url,
						method : "post",
						dataType : "json",
						data : {
							'phoneNo' : phoneNo,
							'checked' : checked
						},
						success : function(data) {
							if (data) {
								//mini.alert("已撤销！");
								datagrid1.reload();
							}
						},
						error : function() {
							mini.alert("操作出现错误！")
						}
					});
				}
			});
		}
		
		function removeBlack() {
			var phoneNos = '';
			var rows = datagrid1.getSelecteds();
			var length = rows.length;
			if (length == 0) {
				mini.alert("请至少选择一条记录.");
				return;
			} else {
				
				for ( var i in rows) {
					var phoneNo = rows[i].PHONE;
					if (phoneNo) {
						if (phoneNos) {
							phoneNos += ',';
						}
						phoneNos += phoneNo;
					}
				}
				pull_white(phoneNos);
			}
		}
	</script>
</body>
</html>